package org.adorsys.aderp.orga.repository;

import java.util.List;

import org.adorsys.aderp.orga.domain.OrgaPerson;
import org.adorsys.aderp.orga.domain.OrgaRelation;
import org.adorsys.aderp.orga.domain.OrgaRelationRole;
import org.adorsys.aderp.orga.domain.OrgaResource;
import org.adorsys.aderp.orga.domain.ResResRelation;
import org.adorsys.aderp.orga.domain.ResourceRelationRole;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.roo.addon.layers.repository.jpa.RooJpaRepository;

@RooJpaRepository(domainType = ResResRelation.class)
public interface ResResRelationRepository {
	
	List<ResResRelation> findByOrgaResource(OrgaResource orgaResource);
	List<ResResRelation> findByTargetResource(OrgaResource orgaResource);

	/**
	 * orgaResource is not null.
	 * 
	 * @param orgaResource
	 * @param pageable
	 * @return
	 */
	Page<ResResRelation> findByOrgaResource(OrgaResource orgaResource, Pageable pageable);
	Page<ResResRelation> findByOrgaResourceAndTargetResource(OrgaResource orgaResource, OrgaResource targetResource, Pageable pageable);
	Page<ResResRelation> findByOrgaResourceAndTargetResourceAndRelationRole(OrgaResource orgaResource, 
			OrgaResource targetResource, ResourceRelationRole relationRole, Pageable pageable);

	/**
	 * orgaResource is null and target Resource is not null
	 * @param targetResource
	 * @param pageable
	 * @return
	 */
	Page<ResResRelation> findByTargetResource(OrgaResource orgaResource, Pageable pageable);
	Page<ResResRelation> findByTargetResourceAndRelationRole(
			OrgaResource targetResource, ResourceRelationRole relationRole, Pageable pageable);
	
	Page<ResResRelation> findByRelationRole(ResourceRelationRole relationRole, Pageable pageable);

}
